﻿using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using XunPan.Web;
using XunPan.Web.Globals;
using System.Web.Security;
using SalePartial.Utility;
using SalePartial.BLL;


partial class User_login_login : System.Web.UI.Page
{

	protected void Login1_LoggedIn(object sender, System.EventArgs e)
	{
		//if (Page.User.Identity.IsAuthenticated)//判断是否通过认证
		//{
		//string[] selectedUsersRoles = Roles.GetRolesForUser(Page.User.Identity.Name);

		string[] UsersToRoles = Roles.GetRolesForUser(Login1.UserName);
		//获取登录用户所属角色
		string tmpstr = "";
		string[] tmparray = null;
		string strsplit = ";";
		// 分隔用字符串
		tmpstr = SecurityUtility.Check_ID(UsersToRoles);

		tmparray = tmpstr.Split(strsplit.ToCharArray(), StringSplitOptions.None);
		Session["mg_power"] = tmparray;

		Session["UserName"] = Login1.UserName;


		MembershipUser CurrentUser = Membership.GetUser(Login1.UserName.ToString());
		Session["UserID"] = (Guid)CurrentUser.ProviderUserKey;

        bool result = UserBLL.StoreUserInfoToSession(Login1.UserName.ToString());


		string target = Request["url"];

		if (string.IsNullOrEmpty(target)) {
			//用户原请求页面为空时
			Login1.DestinationPageUrl = GlobalSetting.UrlHomePage;

		} else {
			//Response.Redirect("~/roles/ManagementWizard.aspx")
			//用户原请求页面不为空时，转到请求页面
			Response.Redirect(target, true);
		}

	}

	protected void Login1_LoginError(object sender, System.EventArgs e)
	{
		Login1.FailureText = "您输入的账户名和密码不匹配，请重新输入。";
		string us = Login1.UserName;
		string pwd = Login1.Password;

		if (Membership.ValidateUser(us, pwd)) {
		//Trace.Warn("ok")
		} else {
			//Dim vendor As MembershipUser = Membership.GetUser(us)
			//Dim tpwd As String

			//tpwd = vendor.ResetPassword()
			//Trace.Warn(tpwd)
		}
	}

	protected void Page_Load(object sender, System.EventArgs e)
	{
		if (Page.User.Identity.IsAuthenticated) {
			Response.Redirect(GlobalSetting.UrlHomePage, true);


		}
	}

    public User_login_login()
    {
        Load += Page_Load;
    }
}
